﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace temportal
{
    class Unit
    {
        public bool isInitialized = false;
        public Game1.inputtypes controlledby;
        public int health;
        public Color tint;
        public Vector2 position;
        public Vector2 velocity;
        public Vector2 acceleration;
        public float fullSpeed;
        public string name;
        SpriteFont namefont;
        Rand rand;

        public Texture2D unitTexture;
        public int width
        {
            get { return unitTexture.Width; }
        }
        public int height
        {
            get { return unitTexture.Height; }
        }

        public Unit(Game1.inputtypes thisinput, String name)
        {
            controlledby = thisinput;
            health = 100;
            this.name = name;
        }

        public Unit(Game1.inputtypes thisinput)
        {
            controlledby = thisinput;
            health = 100;
            this.name = rand.randomName();
            position = new Vector2(0.0f);
            velocity = new Vector2(0.0f);
            acceleration = new Vector2(0.0f);
        }

        public Unit(Game1.inputtypes thisinput, Texture2D t, Vector2 init, Color tinge, string n, SpriteFont sf)
        {
            controlledby = thisinput;
            this.Initialize(t, init, tinge, n, sf);
        }

        public void Initialize(Texture2D texture, Vector2 initPosition, Color t, string nomen, SpriteFont sf)
        {
            health = 100;
            tint = t;
            position = initPosition;
            velocity = new Vector2(0.0f);
            acceleration = new Vector2(0.0f);
            fullSpeed = 8.0f;
            name = nomen;
            namefont = sf;

            unitTexture = texture;

            isInitialized = true;
        }

        public void Update()
        {

        }

        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(unitTexture, position, null, tint, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
            spriteBatch.DrawString(namefont, name, new Vector2(position.X + ((width / 2) - (namefont.MeasureString(name).X / 2)), position.Y - namefont.MeasureString(name).Y - 1), tint);
        }
    }
}
